package com.shiyingzi.security.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.shiyingzi.common.PageableData;
import com.shiyingzi.common.ResponseData;
import com.shiyingzi.security.model.User;
import com.shiyingzi.security.service.ISecurityUserService;
import com.shiyingzi.security.service.IUserService;
import com.shiyingzi.utils.MDFiveUtils;


@RestController
@RequestMapping(value = "User")
public class UserController {

	@Resource(name = IUserService.BEAN_ID)
	private IUserService userService;
	
	@Resource(name = ISecurityUserService.BEAN_ID)
	private ISecurityUserService secUserService;
	
	@RequestMapping(value = "/query", method = { RequestMethod.GET, RequestMethod.POST })
	public PageableData<User> doQuery(int page, int limit, String userName){
		return userService.queryUserList(page, limit, userName);
	}
	@RequestMapping(value = "/getUserById", method = { RequestMethod.GET, RequestMethod.POST })
	public User getUserById(Integer id){
		return secUserService.getUserById(id);
	}
	@RequestMapping(value = "/insert", method = {RequestMethod.GET,RequestMethod.POST })
	public ResponseData inserUser(User User){
		return userService.insertUser(User);
	}
	@RequestMapping(value = "/update", method = {RequestMethod.GET,RequestMethod.POST })
	public ResponseData updateUser(User User){
		return userService.updateUser(User);
	}
	@RequestMapping(value = "/upPasswordById", method = { RequestMethod.GET, RequestMethod.POST })
	public ResponseData upPasswordById(User User){
		User user2=secUserService.getUserById(User.getId());
		user2.setUserPassword(MDFiveUtils.encrypt(User.getUserPassword()));
		return userService.updateUser2(user2);
	}
}
